package com.meichis.yndms.ui.activity;

import android.os.Bundle;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.amap.api.maps2d.model.BitmapDescriptorFactory;
import com.meichis.mcsappframework.entity.Attachment;
import com.meichis.yndms.R;
import com.meichis.yndms.adapter.ImageAdapter;
import com.meichis.yndms.common.MCode;
import com.meichis.yndms.databinding.ActivityVstVisitWorkItemJdBinding;
import com.meichis.yndms.model.Picture;
import com.meichis.yndms.model.VisitWorkItem;
import com.meichis.yndms.ui.common.BaseActivity;

import java.util.ArrayList;

public class Vst_VisitJDLDDPActivity extends BaseActivity   {
    private ActivityVstVisitWorkItemJdBinding binding;

    private VisitWorkItem item;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding.VLocation.onCreate(savedInstanceState);
        binding.VLocation.addMarker(item.getJD().getLatitude(), item.getJD().getLongitude(), BitmapDescriptorFactory.HUE_RED);
    }

    @Override
    protected void setDataBindingContentView() {
        binding = DataBindingUtil.setContentView(this,R.layout.activity_vst_visit_work_item_jd);
        binding.setLifecycleOwner(this);
    }

    @Override
    protected void init() {
        item = (VisitWorkItem) getIntent().getSerializableExtra(MCode.VISITWORKITEM);
        if (item == null || item.getJD() == null) {
            showMsg("没有纪录！");
            close();
            return;
        }

        binding.navigation.txtTitle.setText(item.getProcessName());

        ArrayList<Picture> piclist = new ArrayList<>();
        Picture picture;
        for (Attachment a : item.getAtts()) {
            picture = new Picture();
            picture.setGuid(a.getGUID());
            piclist.add(picture);
        }
        ImageAdapter imageadapter = new ImageAdapter(this, R.layout.activity_signin_photoitem, piclist);
        binding.rc.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
        binding.rc.setAdapter(imageadapter);
    }


    @Override
    protected void onResume() {
        super.onResume();
        binding.VLocation.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        binding.VLocation.onPause();
        binding.VLocation.deactivate();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        binding.VLocation.onSaveInstanceState(outState);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        binding.VLocation.Destroy();
    }
}